﻿using Aluetjen.EmailService.Domain.Models.Message;
using Aluetjen.EmailService.Domain.Models.Pipeline;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Aluetjen.EmailService.Domain.Tests.Models.Pipeline
{
    [TestClass]
    public class ConditionTests
    {
        [TestMethod]
        public void IsSatisfiedBy_Should_Return_True_If_Regex_Matches_Subject()
        {
            var condition = new Condition
                                {
                                    Field = MessageField.Subject,
                                    Regex = "Registration"
                                };

            var message = new MailMessage("test@ezetop.com", "customer@mail.com", "Your Registration at ezetop.com", "Body");

            Assert.IsTrue(condition.IsSatisfiedFor(message));
        }

        [TestMethod]
        public void IsSatisfiedBy_Should_Return_False_If_Regex_Does_Not_Match_Subject()
        {
            var condition = new Condition
            {
                Field = MessageField.Subject,
                Regex = "Registration"
            };

            var message = new MailMessage("test@ezetop.com", "customer@mail.com", "Your Payment at ezetop.com", "Body");

            Assert.IsFalse(condition.IsSatisfiedFor(message));
        }

        [TestMethod]
        public void IsSatisfiedBy_Should_Return_True_If_Regex_Matches_Body()
        {
            var condition = new Condition
            {
                Field = MessageField.Body,
                Regex = "Registration",
            };

            var message = new MailMessage("test@ezetop.com", "customer@mail.com", "Hello customer", "This is about your Registration at ezetop.com");

            Assert.IsTrue(condition.IsSatisfiedFor(message));
        }

        [TestMethod]
        public void IsSatisfiedBy_Should_Return_False_If_Regex_Does_Not_Match_Body()
        {
            var condition = new Condition
            {
                Field = MessageField.Body,
                Regex = "Registration",
            };

            var message = new MailMessage("test@ezetop.com", "customer@mail.com", "Hello customer", "This is about your Payment at ezetop.com");

            Assert.IsFalse(condition.IsSatisfiedFor(message));
        }

        [TestMethod]
        public void IsSatisfiedBy_Should_Return_True_If_Regex_Matches_Any_To()
        {
            var condition = new Condition
            {
                Field = MessageField.To,
                Regex = "@mail.com",
            };

            var message = new MailMessage("test@ezetop.com", "customer@mail.com", "Hello customer", "This is about your Payment at ezetop.com");

            Assert.IsTrue(condition.IsSatisfiedFor(message));
        }

        [TestMethod]
        public void IsSatisfiedBy_Should_Return_True_If_Regex_Matches_From()
        {
            var condition = new Condition
            {
                Field = MessageField.From,
                Regex = "@ezetop.com",
            };

            var message = new MailMessage("test@ezetop.com", "customer@mail.com", "Hello customer", "This is about your Payment at ezetop.com");

            Assert.IsTrue(condition.IsSatisfiedFor(message));
        }
    }
}
